package demo1;

import java.util.Stack;

public class MyQueue {
    private Stack<Integer> stack1;
    private Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int val) {
        stack1.push(val);
    }

    public int pop() {
        if(!stack2.isEmpty()) {
            return stack2.pop();
        } else {
            while(!stack1.isEmpty()) {
                int val = stack1.pop();
                stack2.push(val);
            }
            return stack2.pop();
        }
    }

    public int peek() {
        if(!stack2.isEmpty()) {
            return stack2.peek();
        } else {
            while(!stack1.isEmpty()) {
                int val = stack1.pop();
                stack2.push(val);
            }
            return stack2.peek();
        }
    }

    public boolean isEmpty() {
        return stack1.isEmpty() && stack2.isEmpty();
    }
}
